package cn.itcast.Service.impl;

import cn.itcast.Service.CourseService;
import cn.itcast.common.PageBean;
import cn.itcast.domain.dto.CourseDTO;
import cn.itcast.domain.dto.PageDTO;
import cn.itcast.domain.vo.CourseVO;
import cn.itcast.mapper.CourseMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zsw
 * @Date: 2024/1/18 21:51
 */
@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public PageBean getCourseList(PageDTO pageDTO) {
        Integer pageNum = pageDTO.getPageNum();
        Integer pageSize = pageDTO.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<CourseVO> courseList = courseMapper.getCourseList();
        Page<CourseVO> page = (Page) courseList;
        PageBean pageBean = new PageBean(page.getTotal(), page.getResult());
        return pageBean;
    }

    @Override
    public int addCourse(CourseDTO courseDTO) {
        int i = courseMapper.addCourse(courseDTO);
        return i;
    }

    @Override
    public int updateCourse(CourseDTO courseDTO) {
        int i = courseMapper.updateCourse(courseDTO);
        return i;
    }

    @Override
    public int deleteCourseById(Integer CourseId) {
        int i = courseMapper.deleteCourseById(CourseId);
        return i;
    }
}
